﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
using System.ComponentModel;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Data;
using System.Globalization;
using System.Collections.ObjectModel;
using System.Diagnostics;

namespace QLDIAOC
{
    class GetDataFromSQL
    {
        public SqlConnection m_SqlConnection;
        public SqlCommand m_SqlCommand;
        public SqlDataAdapter m_SqlDataAdapter;
        public SqlDataReader m_SqlDataReader;
        public DataSet m_DataSet;
        public DataTable m_DataTable;
        public DataRowView m_RowDataGrid = null;

        public GetDataFromSQL(SqlConnection _SCN)
        {
            m_SqlConnection = _SCN;
        }

        public DataTable MakeTable(String _nameOfPro, String _nameOfTable)
        {
            try
            {
                m_SqlCommand = new SqlCommand(_nameOfPro, m_SqlConnection);
                m_SqlCommand.CommandType = CommandType.StoredProcedure;
                m_SqlDataAdapter = new SqlDataAdapter();
                m_SqlDataAdapter.SelectCommand = m_SqlCommand;
                m_DataSet = new DataSet();
                m_SqlDataAdapter.Fill(m_DataSet, _nameOfTable);
                m_DataTable = m_DataSet.Tables[_nameOfTable];
                m_SqlDataAdapter.Dispose();
                return m_DataTable;
            }
            catch (SqlException es)
            {
                MessageBox.Show(es.Message.ToString());
                return null;
            }
        }


        public DataRowView GetDataRow(DataGrid _dataGrid)
        {
            m_RowDataGrid = _dataGrid.SelectedCells[0].Item as DataRowView;
            return m_RowDataGrid;
        }



    }
}
